@echo off
setlocal

REM Set default configuration to Debug
set CONFIGURATION=Debug

REM Check if Release parameter is passed
if /i "%1"=="Release" set CONFIGURATION=Release

echo Building MouseKeyboardOperationSimulator project in %CONFIGURATION% mode...
echo.

REM Using Visual Studio 2022 MSBuild to build the project
"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" "MouseKeyboardOperationSimulator.sln" /p:Configuration=%CONFIGURATION%

if %errorlevel% equ 0 (
    echo.
    echo Project built successfully!
    echo Copying Newtonsoft.Json.dll to output directory...
    
    REM Copy Newtonsoft.Json.dll to the output directory
    copy "packages\Newtonsoft.Json.13.0.4\lib\net48\Newtonsoft.Json.dll" "MouseKeyboardOperationSimulator\bin\%CONFIGURATION%\*" >nul
    
    if %errorlevel% equ 0 (
        echo Newtonsoft.Json.dll copied successfully!
        echo.
        echo Executable file is located in MouseKeyboardOperationSimulator\bin\%CONFIGURATION% directory
    ) else (
        echo Failed to copy Newtonsoft.Json.dll
    )
) else (
    echo.
    echo Project build failed, please check the error message.
)

REM pause